home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvdmx.exe / TVDMXBUF.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-16  |  22KB  |  846 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    tvDMXBUF  --Buffered Data Editing Unit        }
  5. {    tvDMX     --data editing project (ver 1.4)    }
  6. {                            }
  7. {    Copyright (c) 1992  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Unit tvDMXBUF;
  15.  
  16. {$B-,D-,R-,O+,X+,V- }
  17.  
  18. interface
  19.  
  20. uses  
  21.     Objects, Drivers, Views, Dialogs, App, MsgBox,
  22.     RSet, DmxGizma, tvDMX, StdDMX;
  23.  
  24. const
  25.     EmptySlot    =  -1;
  26.  
  27. type
  28.     PSlot    = ^TSlot;
  29.     TSlot    =  RECORD
  30.         Data   : pointer;
  31.         RowNum : integer;
  32.     end;
  33.  
  34.  
  35.     PRowSlots    = ^TRowSlots;
  36.     TRowSlots    =  array [0..99] of TSlot;
  37.  
  38.  
  39.     PDmxEditBuf     = ^TDmxEditBuf;
  40.     PDmxStreamBuf   = ^TDmxStreamBuf;
  41.     PDmxExpBuf      = ^TDmxExpBuf;
  42.     PDmxExpRecInd   = ^TDmxExpRecInd;
  43.     PDmxBufWin      = ^TDmxBufWin;
  44.     PDmxExpBufWin   = ^TDmxExpBufWin;
  45.     PDmxEditRecBuf  = ^TDmxEditRecBuf;
  46.  
  47.  
  48.     TDmxEditBuf   =  OBJECT (TDmxEditor)
  49.         NumSlots    :  integer;
  50.         RowSlot     :  PRowSlots;
  51.         KeyFields   :  set of byte;
  52.         KeyAltered  :  boolean;
  53.         Expandable  :  boolean;
  54.         Appending   :  boolean;
  55.         StepMode    :  boolean;
  56.       constructor Load (var S : TStream);
  57.       procedure Store (var S : TStream);
  58.       procedure LoadStruct (var S : TStream);  VIRTUAL;
  59.       procedure MakeSlots;
  60.       procedure ResetSlots;
  61.       procedure InitStruct (var ATemplate );  VIRTUAL;
  62.       procedure DoneStruct;  VIRTUAL;
  63.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  64.       procedure SetState (AState : word; Enable : boolean);  VIRTUAL;
  65.       function  DataAt (RecNum : integer)  : pointer;  VIRTUAL;
  66.       procedure SetUpRecord;  VIRTUAL;
  67.       procedure EvaluateRecord;  VIRTUAL;
  68.       procedure EvaluateField;  VIRTUAL;
  69.       procedure ZeroizeField (Whole : boolean; Field : pDMXfieldrec);  VIRTUAL;
  70.       procedure ResetSize;
  71.       function  RecordLimit : integer;  VIRTUAL;
  72.       function  ErrorFunc : boolean;  VIRTUAL;
  73.       function  SeekRec (RecNum : integer) : boolean;  VIRTUAL;
  74.       function  SeekEnd : boolean;  VIRTUAL;
  75.       function  ReadRec (var RecData ) : boolean;  VIRTUAL;
  76.       function  WriteRec (var RecData ) : boolean;  VIRTUAL;
  77.       private
  78.         NewRecord   :  boolean;  { indicates this is a new record }
  79.     end;
  80.  
  81.  
  82.     TDmxStreamBuf =  OBJECT (TDmxEditBuf)
  83.         Prefix      :  pointer;
  84.         PrefixSize  :  integer;
  85.       procedure LoadStruct (var S : TStream);  VIRTUAL;
  86.       procedure StoreStruct (var S : TStream);  VIRTUAL;
  87.       function  RecordLimit : integer;  VIRTUAL;
  88.       function  ErrorFunc : boolean;  VIRTUAL;
  89.       function  SeekRec (RecNum : integer) : boolean;  VIRTUAL;
  90.       function  SeekEnd : boolean;  VIRTUAL;
  91.       function  ReadRec (var RecData ) : boolean;  VIRTUAL;
  92.       function  WriteRec (var RecData ) : boolean;  VIRTUAL;
  93.     end;
  94.  
  95.  
  96.     TDmxExpBuf    =  OBJECT (TDmxStreamBuf)
  97.       procedure InitData (var AData );  VIRTUAL;
  98.     end;
  99.  
  100.  
  101.     TDmxExpRecInd =  OBJECT (TDmxRecInd)
  102.       procedure Draw;  VIRTUAL;
  103.     end;
  104.  
  105.  
  106.     TDmxBufWin    =  OBJECT (TDmxWindow)
  107.       procedure InitDMX (ATemplate : string;  var AData;
  108.                          ALabels, ARecInd  : PDmxLink;
  109.                          BSize  : longint);  VIRTUAL;
  110.     end;
  111.  
  112.  
  113.     TDmxExpBufWin =  OBJECT (TDmxWindow)
  114.       procedure InitDMX (ATemplate : string;  var AData;
  115.                          ALabels, ARecInd  : PDmxLink;
  116.                          BSize  : longint);  VIRTUAL;
  117.       function  NewRecInd (Len : integer)  : PDmxLink;  VIRTUAL;
  118.     end;
  119.  
  120.  
  121.     TDmxEditRecBuf  =  OBJECT (TDmxEditBuf)
  122.         RecPosition : longint;
  123.       procedure InitData (var AData );  VIRTUAL;
  124.       procedure ZeroizeRecord;  VIRTUAL;
  125.       function  SeekRec (RecNum : integer) : boolean;  VIRTUAL;
  126.       function  SeekEnd : boolean;  VIRTUAL;
  127.       procedure DeleteRec;  VIRTUAL;
  128.       function  WriteRec (var RecData ) : boolean;  VIRTUAL;
  129.       function  AppendRec (var RecData ) : boolean;  VIRTUAL;
  130.       function  UpdateRec (var RecData ) : boolean;  VIRTUAL;
  131.       function  FirstRec : boolean;  VIRTUAL;
  132.       function  LastRec : boolean;  VIRTUAL;
  133.       function  NextRec : boolean;  VIRTUAL;
  134.       function  PrevRec : boolean;  VIRTUAL;
  135.     end;
  136.  
  137.  
  138. const
  139.     RDmxStreamBuf :  TStreamRec = (
  140.         ObjType:   cmDMX + 10;
  141.         VmtLink:   ofs (TypeOf (TDmxStreamBuf)^);
  142.         Load:      @TDmxStreamBuf.Load;
  143.         Store:     @TDmxStreamBuf.Store
  144.       );
  145.  
  146.     RDmxExpBuf    :  TStreamRec = (
  147.         ObjType:   cmDMX + 11;
  148.         VmtLink:   ofs (TypeOf (TDmxExpBuf)^);
  149.         Load:      @TDmxExpBuf.Load;
  150.         Store:     @TDmxExpBuf.Store
  151.       );
  152.  
  153.     RDmxExpRecInd :  TStreamRec = (
  154.         ObjType:   cmDMX + 12;
  155.         VmtLink:   ofs (TypeOf (TDmxExpRecInd)^);
  156.         Load:      @TDmxExpRecInd.Load;
  157.         Store:     @TDmxExpRecInd.Store
  158.       );
  159.  
  160.     RDmxBufWin    :  TStreamRec = (
  161.         ObjType:   cmDMX + 13;
  162.         VmtLink:   ofs (TypeOf (TDmxBufWin)^);
  163.         Load:      @TDmxBufWin.Load;
  164.         Store:     @TDmxBufWin.Store
  165.       );
  166.  
  167.     RDmxExpBufWin :  TStreamRec = (
  168.         ObjType:   cmDMX + 14;
  169.         VmtLink:   ofs (TypeOf (TDmxExpBufWin)^);
  170.         Load:      @TDmxExpBufWin.Load;
  171.         Store:     @TDmxExpBufWin.Store
  172.       );
  173.  
  174.  
  175. implementation
  176.  
  177.  
  178.   { ══ TDmxEditBuf ═══════════════════════════════════════════════════════ }
  179.  
  180.  
  181. constructor TDmxEditBuf.Load (var S : TStream);
  182. begin
  183.   TDmxEditor.Load (S);
  184.   S.Read (KeyFields,  sizeof (KeyFields));
  185.   S.Read (Expandable, sizeof (Expandable));
  186.   S.Read (StepMode,   sizeof (StepMode));
  187. end;
  188.  
  189.  
  190. procedure TDmxEditBuf.Store (var S : TStream);
  191. begin
  192.   TDmxEditor.Store (S);
  193.   S.Write (KeyFields,  sizeof (KeyFields));
  194.   S.Write (Expandable, sizeof (Expandable));
  195.   S.Write (StepMode,   sizeof (StepMode));
  196. end;
  197.  
  198.  
  199. procedure TDmxEditBuf.LoadStruct (var S : TStream);
  200. begin
  201.   TDmxEditor.LoadStruct (S);
  202.   MakeSlots;
  203. end;
  204.  
  205.  
  206. procedure TDmxEditBuf.MakeSlots;
  207. var i  : integer;
  208. begin
  209.   If InitValid and (RecordSize > 0) then
  210.     begin
  211.     NumSlots := ScreenHeight;
  212.     If (HiResScreen and (NumSlots < 30)) then NumSlots := 46;
  213.     If (NumSlots < Size.Y) then NumSlots := Size.Y;
  214.     GetMem (RowSlot, NumSlots * sizeof (TSlot));
  215.     fillchar (RowSlot^, NumSlots * sizeof (TSlot), 0);
  216.     For i := 0 to pred (NumSlots) do
  217.       begin
  218.       If ((MaxAvail shr 4) > RecordSize) then
  219.         begin
  220.         RowSlot^ [i].RowNum := EmptySlot;
  221.         GetMem (RowSlot^ [i].Data, RecordSize);
  222.         end
  223.        else
  224.         InitValid := FALSE;
  225.       end;
  226.     end;
  227. end;
  228.  
  229.  
  230. procedure TDmxEditBuf.ResetSlots;
  231. var i : integer;
  232. begin
  233.   If (NumSlots > 0) then
  234.     For i := 0 to pred (NumSlots) do RowSlot^ [i].RowNum := EmptySlot;
  235. end;
  236.  
  237.  
  238. procedure TDmxEditBuf.InitStruct (var ATemplate );
  239. begin
  240.   TDmxEditor.InitStruct (ATemplate);
  241.   MakeSlots;
  242. end;
  243.  
  244.  
  245. procedure TDmxEditBuf.DoneStruct;
  246. var i : integer;
  247. begin
  248.   If (RowSlot <> nil) then
  249.     begin
  250.     For i := 0 to pred (NumSlots) do
  251.       If (RowSlot^ [i].Data <> nil) then FreeMem (RowSlot^ [i].Data, RecordSize);
  252.     FreeMem (RowSlot, NumSlots * sizeof (TSlot));
  253.     RowSlot  := nil;
  254.     NumSlots := 0;
  255.     end;
  256.   TDmxEditor.DoneStruct;
  257. end;
  258.  
  259.  
  260. procedure TDmxEditBuf.HandleEvent (var Event : TEvent);
  261. begin
  262.   With Event do
  263.     If (What = evBroadcast) and (NumSlots > 0) and
  264.         (((Command = cmDMX_DrawData) and (WorkingData = InfoPtr))
  265.        or
  266.          ((Command = cmDMX_Draw)
  267.         and (InfoPtr <> @Self)
  268.         and (PDmxScroller (InfoPtr)^.WorkingData = WorkingData)))
  269.      then
  270.       begin
  271.       ResetSlots;
  272.       end;
  273.   TDmxEditor.HandleEvent (Event);
  274. end;
  275.  
  276.  
  277. procedure TDmxEditBuf.SetState (AState : word; Enable : boolean);
  278. begin
  279.   If Enable and (AState and sfFocused <> 0) and (not RecordSelected) and
  280.      Expandable and (CurrentField <> nil) then
  281.     ResetSize;
  282.   TDmxEditor.SetState (AState, Enable);
  283. end;
  284.  
  285.  
  286. function